package com.xmim.server.examples;

import com.xmim.fulcrum.node.FulcrumServiceNode;
import com.xmim.fulcrum.node.FulcrumUserNode;
import com.xmim.fulcrum.session.FulcrumNodeBind;

import java.util.Map;

public class ZkFulcrumUserPathCache extends ZkFulcrumPathCache<FulcrumUserNode> {


    public ZkFulcrumUserPathCache(ZKFulcrumDiscover discover) {
        super(discover);
    }

    @Override
    protected void onAddNode(FulcrumUserNode node) {
        super.onAddNode(node);
        FulcrumServiceNode localNode = discover.getLocalNode();
        Map<String, FulcrumNodeBind> sessionsLocalCache = discover.getSessionsCaches();
        sessionsLocalCache.put(node.getSessionId(), new FulcrumNodeBind(node, localNode));
    }

    @Override
    public String getPath() {
        return this.discover.getFactory().getConfig().getUserNodePath();
    }

    @Override
    public String getSerialPath() {
        return this.discover.getFactory().getConfig().getUserNodePath()
                + "/" +
                this.discover.getFactory().getConfig().getSeqPrefixPath();
    }
}
